import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';


//推修订单列表
class PushRepair extends StatefulWidget {
  @override
  _PushRepairState createState() => _PushRepairState();
}

class _PushRepairState extends State<PushRepair> {
  List<String> _pushList = [
    "新推修",
    "定损中",
    "维修中",
    "待开票",
    "已开票",
    "已退票",
    "待结算",
    "已结算",
    "已撤案"
  ];//事件列表
  bool isShow = false; //默认隐藏
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xffF0F0F0),
      appBar: customAppBar(context,title: "推修订单列表"),
      body: CustomScrollView(
        slivers: [

          //事件列表
          SliverToBoxAdapter(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(4)
              ),
              margin: EdgeInsets.only(top: setWidth(10),left: setWidth(12),right: setWidth(12)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    padding: EdgeInsets.only(left: setWidth(15),right: setWidth(15),bottom: setWidth(20),top: setWidth(15)),
                    child: Text("事件列表",style: TextStyle(color: Color(0xff323232),fontSize: setSp(16),fontWeight: FontWeight.w600),),
                  ),
                  Container(
                      color: Colors.white,
                      child: StaggeredGridView.countBuilder(
                        physics: NeverScrollableScrollPhysics(),
                        shrinkWrap: true,
                        crossAxisCount: 4,
                        mainAxisSpacing: setWidth(30),
                        crossAxisSpacing: setWidth(10),
                        staggeredTileBuilder: (i) {
                          return StaggeredTile.fit(1);
                        },
                        itemCount: isShow ? _pushList.length : 4,
                        itemBuilder: (context, index) {
                          return GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              onTap: () {
                                urlPush(context, "yuntu://push_repair_category?title=${_pushList[index]}&type=$index");

                              },
                              child: _gridItem("100", _pushList[index]));
                        },
                      )),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: (){
                      setState(() {
                        isShow = !isShow;
                      });
                    },
                    child: Container(
                      padding: EdgeInsets.only(bottom: setWidth(20)),
                      color: Colors.white,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            child: Text(
                              isShow? "收起":"展开",
                              style: TextStyle(
                                  color: Color(0xff989898),
                                  fontSize: setSp(15),
                                  fontWeight: FontWeight.w500),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(5),
                          ),
                          SizedBox(width: setWidth(15),
                            height: setWidth(10),
                            child: Image.asset(isShow?"assets/images/home_up.png":"assets/images/home_done.png",width: setWidth(15),
                              height: setWidth(10),fit: BoxFit.cover,),
                          ),
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),


          SliverToBoxAdapter(
            child:  Container(
              padding: EdgeInsets.only(left: setWidth(15),top: setWidth(18)),
              child: Text("待处理订单",style: TextStyle(color: Color(0xff323232),fontSize: setSp(16),fontWeight: FontWeight.w600),),
            ),
          ),
          //推修列表
          SliverList(delegate: SliverChildBuilderDelegate((context,index){
            return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: (){
                 switch(index){
                   case 0 :urlPush(context, "yuntu://push_repair_details?title=${_pushList[index]}");break;
                   case 1 :urlPush(context, "yuntu://in_loss_assessment?title=${_pushList[index]}");break;
                   case 2 :urlPush(context, "yuntu://in_maintenance?title=${_pushList[index]}");break;
                   case 3 :urlPush(context, "yuntu://wait_back_bill?title=${_pushList[index]}");break;
                   case 4 :urlPush(context, "yuntu://repair_await_settlement?title=${_pushList[index]}");break;
                   case 5 :urlPush(context, "yuntu://repair_refunded?title=${_pushList[index]}");break;
                   case 6 :urlPush(context, "yuntu://await_balance?title=${_pushList[index]}");break;
                   case 7 :urlPush(context, "yuntu://repair_have_settlement?title=${_pushList[index]}");break;
                   case 8 :urlPush(context, "yuntu://repair_withdrawn?title=${_pushList[index]}");break;
                 }

                },
                child: _pushRepairItem(state: _pushList[index]));
          },
              childCount:_pushList.length
          )),
        ],
      ),
      
    );
  }

  //事件类型
  Widget _gridItem(String num, String title) {
    return Container(
      child: Column(
        children: [
          Container(
            child: Text(
              num,
              style: TextStyle(
                  color: Color(0xff323232),
                  fontSize: setSp(24),
                  fontWeight: FontWeight.w600),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
          SizedBox(
            height: setWidth(10),
          ),
          Container(
            child: Text(title,
                style: TextStyle(
                  color: Color(0xff686868),
                  fontSize: setSp(14),)),
          )
        ],
      ),
    );
  }

  Widget _pushRepairItem({String state}) {
    return Container(
      margin: EdgeInsets.only(left: setWidth(15),right: setWidth(15),top: setWidth(15)),
      padding: EdgeInsets.only(left: setWidth(14),right: setWidth(14),bottom: setWidth(18)),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(2)
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          //处理编号
          _dealingNum(num: "AE11232498",state: state),
          //车辆牌号
          _carNumber(type: "A98U89",time: "2020-01-21 10:10"),
          //车辆型号
          _carInfo("路虎极光 雅致版GF236"),
        ],
      ),

    );
  }

  //处理编号
  Widget _dealingNum({String num,String state}){
    return Container(
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(text: TextSpan(
                children: [
                  TextSpan(text:"处理编号:",style: TextStyle(color: Color(0xff999999),fontSize: setSp(14))),
                  WidgetSpan(child: SizedBox(
                    width: setWidth(3),
                  )),
                  TextSpan(text:num,style: TextStyle(color: Color(0xff323232),fontSize: setSp(14))),
                ]
            )),
          ),
          Row(
            children: [
              Container(
                height: setWidth(18.5),
                width: setWidth(32),
                color: Color(0xffE5E5E5),
              ),
              SizedBox(
                width: setWidth(10.5),
              ),
              Container(
                child:  Text(state,style: TextStyle(color: Color(0xffFF921A),fontSize: setSp(13))),
              ),
            ],
          )
        ],
      ),
    );
  }

  //车辆牌号
  Widget _carNumber({String type,String time}){
    return Container(
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(text: TextSpan(
                children: [
                  TextSpan(text:"车辆牌号:",style: TextStyle(color: Color(0xff999999),fontSize: setSp(14))),
                  WidgetSpan(child: SizedBox(
                    width: setWidth(3),
                  )),
                  TextSpan(text:type,style: TextStyle(color: Color(0xff323232),fontSize: setSp(14))),
                ]
            )),
          ),
          Container(
            child:  Text(time,style: TextStyle(color: Color(0xff999999),fontSize: setSp(13))),
          )
        ],
      ),
    );

  }

  //车辆型号
  Widget _carInfo(String info){
    return Container(
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(text: TextSpan(
                children: [
                  TextSpan(text:"车辆型号:",style: TextStyle(color: Color(0xff999999),fontSize: setSp(14))),
                  WidgetSpan(child: SizedBox(
                    width: setWidth(3),
                  )),
                  TextSpan(text:info,style: TextStyle(color: Color(0xff323232),fontSize: setSp(14))),
                ]
            )),
          ),
        ],
      ),
    );
  }


}
